#include "SimpleTexture.h"
#include <QSGVertexColorMaterial>
#include <QSGGeometry>
#include <QSGGeometryNode>
#include <QSGMaterial>
#include <QSGTransformNode>
#include <QSGSimpleTextureNode>
#include "tool.h"
SimpleTextureItem::SimpleTextureItem(QQuickItem* parent)
    : Super(parent)
{
    setFlag(Super::ItemHasContents);
}

SimpleTextureItem::~SimpleTextureItem() { }

QSGNode* SimpleTextureItem::updatePaintNode(QSGNode* oldNode, UpdatePaintNodeData* data)
{
    (void)data;

    QSGSimpleTextureNode *textureNode = nullptr;
    if (!oldNode)
    {
        auto path = getImagePath( imgPath + QStringLiteral("qz.png"));
        QImage image(path);
        qWarning() << path << image.width() << image.height();

        auto texture = window()->createTextureFromImage(image);
        textureNode = new QSGSimpleTextureNode;
        textureNode->setTexture(texture);
        textureNode->setOwnsTexture(true);
        textureNode->setRect(0, 0, image.width(), image.height());
        textureNode->setFiltering(QSGTexture::Linear);
    }
    else
    {
        textureNode = static_cast<QSGSimpleTextureNode *>(oldNode);
    }
    return textureNode;
}

